package cn.dnui_zzh807.dnuifood_16110100807.model;

import java.util.List;

import cn.dnui_zzh807.dnuifood_16110100807.bean.ShopBean;
import cn.dnui_zzh807.dnuifood_16110100807.common.Constants;
import cn.dnui_zzh807.dnuifood_16110100807.listener.OnRetrofitListener;
import cn.dnui_zzh807.dnuifood_16110100807.service.ShopService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Dobby on 2018/10/29.
 */

public class ShopModel extends RetrofitBaseModel  {
    private ShopService shopService;
    public ShopModel(){

        retrofit=new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .addConverterFactory(GsonConverterFactory
                        .create())
                .build();

        this.shopService = retrofit.create(ShopService.class);
    }
    public void getALLShops(final OnRetrofitListener listener){


        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ShopService shopService = retrofit.create(ShopService.class);
        Call<List<ShopBean>> call = shopService.getALLShops();
        Callback<List<ShopBean>> callback = new Callback<List<ShopBean>>() {
            @Override
            public void onResponse(Call<List<ShopBean>> call, Response<List<ShopBean>> response) {
                listener.onSuccess(response.body(),3);


            }

            @Override
            public void onFailure(Call<List<ShopBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
//        Call<List<Shop>> call = shopService.getALLShops();
//        bindCallback(call,listener,Constants.GETALLSHOPS);


    }
}
